home *** CD-ROM | disk | FTP | other *** search
- Path: arlut.utexas.edu!usenet
- From: Lee Crites <crites@arlut.utexas.edu>
- Newsgroups: comp.lang.c++
- Subject: Re: Is there a standard for * and & placement style?
- Date: 22 Feb 1996 19:57:14 GMT
- Organization: Applied Research Laboratories - The University of Texas at Austin
- Message-ID: <4gihqq$1s9@ns1.arlut.utexas.edu>
- References: <3128BD31.4AF8@wildfire.com> <marnoldDn27q9.Is0@netcom.com> <4gckd5$bc7@clarknet.clark.net> <marnoldDn63vB.H6n@netcom.com>
- NNTP-Posting-Host: squid.arlut.utexas.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.01 9000/730)
- X-URL: news:marnoldDn63vB.H6n@netcom.com
-
- For me, I prefer to put the * with the type. So I prefer things like:
-
- char* FirstName;
- struct goober* goo;
-
- But then again, I only do one per line, just as Matt was stating in his
- message. I also like to include initialization with the variable declarations
- if at all possible. Yes, I know that c++ includes initialization, but I don't
- trust it. Plus, I use languages that *don't* have that feature, so to keep my
- code consistent, I initialize all variables.
-
- >Some may think "one concept per line" to be silly, but I've found it
- >also makes maintaining code a bit simpler (for less intra-line edits,
-
- Not only have I found that it is not silly, but when I have to maintain someone
- else's code I am sometimes forced to resturcture it just to figure out what
- they were trying to do. When you hear people say that things like "...it'd
- just be faster to write it from scratch than to try to fix the original
- program..." you are hearing someone who has been bitten by this kind of bug.
- Even the most obtuse program can be more easily maintained if it is structured
- properly.
-
- >Just because the langauge allows a particular syntax does not mean
- >you have to use it or structure your coding practices around it. I
-
- I have to add my wholehearted support to what Matt said here.
-
- We work in multiple languages. At this time I am actively working on
- programs/systems in C, C++, Pascal (BP7, TP5, and TP6), PAL, and PICKBasic.
- (and I have just talked with someone who would like some stuff done in either
- logo or lisp)
-
- The trick is to find a *style* that works and use it in *all* of your
- programming. I have a c/c++-programmer-type here that loves to ride me because
- I write a slightly different style of code than he does. But my indentions
- look the same in all of my programs. Period. It is logical enough that anyone
- can follow what I am doing. In fact, if it wasn't for the fact that this guy
- loves to ride my case about using pascal, he'd probably have never noticed that
- my indention style is not the same as his.
-
- Getting a convention and sticking with it is the only way that you can write
- and maintain large programs.
-
- But the most profound statement above is "...just because the language allows a
- particular syntax doesn't mean you have to use it..."!
-
- How often have we seen things like "while (*a++ = *b++) ;" used? No comments,
- no explainations, just cryptic code. We are no longer in a position where we
- have to hand optimize our code. We no longer have to worry about a byte of ram
- saved here and a byte of ram saved there. (real-time embedded systems are an
- exception to this, of course) We aren't writing programs that will run on an
- 8088 with 64k of ram any more. We aren't having to trim characters out of our
- source files because the compiler can't handle a file that big or the diskette
- only holds 160k. I remember those days, as do many of you. They are
- thankfully gone.
-
- It's time that we woke up and realized that maintainability is more important
- than saved keystrokes. It's time we realized that packing a dozen, or more,
- commands into a single line of code isn't the quintessential sign of manhood it
- was once thought to be.
-
- We need standards that help us to maintain the code. Things like:
-
- -- each line of code performs only one command
- -- use brackets to specify order
- -- use intelligent variable names
- -- include lots of internal docu
- -- paragraph and indent structures, including blank lines; use a standard
- style throughout all code
- -- each method/subroutine should do one thing, and one thing only
- -- each method/subroutine should be small enough that it can be totally
- understood in 30 seconds or so
- -- objects should hide all variables and constants behind accessor methods
- -- all program variables should be initialized
- -- in objects the constructor should initialize all variables
- -- keep casting to a minimum (if you *need* an int, make an int, not a char)
-
- The list can go on, but I think you get my drift.
-
- Lee
-
-